
/**
 * Description: <p>陕西省地税渭南-餐饮业定税系统</p>
 * Content Desc:<p><p>
 * Copy Right of Personal Tangtao 2007-2020
 * @author Andy
 * @version 1.0
 */
package com.sxds.wn.service.web;

import com.sxds.wn.exception.DataAccessException;
import com.sxds.wn.exception.ParameterException;
import com.sxds.wn.security.PasswordEncryptProvider;
import com.sxds.wn.security.UserDao;
import com.sxds.wn.security.dto.User;
import com.sxds.wn.service.BaseService;
import com.sxds.wn.service.IService;


/**
 * Description: <p>安全服务实现</p>
 * Content Desc:<p>提供密码修改服务<p>
 * Copy Right of Geong
 * @author Tangtao Email:<a href="mailto:tangtao7481@yahoo.com.cn">tangtao7481@yahoo.com.cn</a>
 * @version 1.0 Create Date:@2010-4-22
 */
public class UserService extends BaseService implements IService {

	//密码检验接口
	private PasswordEncryptProvider passwordEncrypt;
	//用户数据访问接口
	private UserDao userDao;
	
	/* (non-Javadoc)
	 * @see com.cfets.dcs.service.BaseService#checkPermission()
	 */
	@Override
	protected boolean checkPermission() throws SecurityException {
		return false;
	}

	/**
	 * 修改用户密码
	 * @throws DataAccessException
	 */
	private void updatePassword() throws DataAccessException {
		String oldPassword = this.request.getHttpRequest().getParameter("oldPassword");
		String newPassword = this.request.getHttpRequest().getParameter("newPassword");
		User persistUser = userDao.queryUser(user);
		if( persistUser==null ) {
			this.response.setOk(Boolean.FALSE);
			this.response.setResponseMessage("用户不存在，无法修改！");
			return;
		}
		//验证密码是否正确 
		String encryptPassword = passwordEncrypt.encrypt(oldPassword);
		if( !encryptPassword.equals(persistUser.getUserPassword()) ){
			this.response.setOk(Boolean.FALSE);
			this.response.setResponseMessage("您提供的原密码有误，无法修改！");
			return;
		}
		user.setUserPassword(passwordEncrypt.encrypt(newPassword));
		this.userDao.updateUser(user);
		this.response.setOk(true);
		this.response.setResponseMessage("修改密码成功！");
	}

	/* (non-Javadoc)
	 * @see com.cfets.dcs.service.BaseService#validateParameters()
	 */
	@Override
	protected boolean validateParameters() throws ParameterException {
		return false;
	}

	/**
	 * @param passwordEncrypt the passwordEncrypt to set
	 */
	public void setPasswordEncrypt(PasswordEncryptProvider passwordEncrypt) {
		this.passwordEncrypt = passwordEncrypt;
	}

	/**
	 * @param userDao the userDao to set
	 */
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
